#!/bin/env bash

usage(){
    echo "useage:"
    echo "-h help"
    echo "-j path of jdk"
    echo "-m path of mysql"
    exit 0
}


profile_path=/etc/profile

java_home(){
    echo "$1"
    {
        echo "#JAVA"
        echo "export JAVA_HOME=$1"
        echo "export PATH=\${JAVA_HOME}/bin:\$PATH"
        echo "export CLASSPATH=.:\${JAVA_HOME}/lib/dt.jar:\${JAVA_HOME}/lib/tools.jar"
    } >> ${profile_path}
}

mysql(){
    echo "$1"
    {
        echo "#MySQL"
        echo "export PATH=$1/bin:"'$PATH'
    } >> ${profile_path}
}


while getopts 'hj:m:' OPT;do
    case $OPT in
        j) java_home "$OPTARG";;
        m) mysql "$OPTARG";;
        h) usage;;
        ?) usage;;
    esac
done